package com.chushouya.controller.common;

import com.general.framework.core.enums.LimitType;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.RateLimiter;
import com.chushouya.manager.dto.admin.captcha.CaptchaDTO;
import com.chushouya.manager.service.admin.CaptchaService;
import com.chushouya.common.constant.ServiceType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 验证码操作处理
 */
@Api(tags = "验证码图片")
@RestController
@RequestMapping(ServiceType.COMMON + "/captcha/")
public class CaptchaController {

    @Resource
    private CaptchaService captchaService;

    @RateLimiter(time = 5, count = 3, limitType = LimitType.IP)
    @ApiOperation("获取验证码图片")
    @GetMapping("/getCaptchaImage")
    public Response<CaptchaDTO> getCaptchaImage() {
        return Response.success(captchaService.getCaptcha());
    }

}
